package gui.jfram;

import bll.model.UserModel;
import bll.service.StudentService;
import bll.service.UserService;
import bll.serviceimpl.StudentServiceImpl;
import bll.serviceimpl.UserServiceImpl;
import dal.entity.Student;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class AddFrame extends JFrame {
    private JLabel jLabel1;
    private JTextField jTextField1;
    private JLabel jLabel2;
    private JPasswordField jPasswordField1;
    private JButton jButton1;
    private JButton jButton2;

    public AddFrame()  {
        jLabel1 = new JLabel("用户名：");
        jTextField1 = new JTextField(20);
        jLabel2 = new JLabel("密码");
        jPasswordField1 = new JPasswordField(20);
        jButton1 = new JButton("确定");
        jButton2 = new JButton("取消");
        this.setLayout(new GridLayout(3,2));
        this.add(jLabel1);
        this.add(jTextField1);
        this.add(jLabel2);
        this.add(jPasswordField1);
        this.add(jButton1);
        this.add(jButton2);
        this.setTitle("添加学生");
        this.setSize(300, 200);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);

        jButton1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                StudentService studentService = new StudentServiceImpl();
                Student student = new Student();
                student.setSname(jTextField1.getText());
                student.setSnumber(jPasswordField1.getText());
                student.setSage(22);
                student.setSphone("19137415669");
                student.setSaddress("shnegda");
                if(studentService.addStudent(student)){
                    JOptionPane.showMessageDialog(AddFrame.this,"添加成功");

                }else{
                    JOptionPane.showMessageDialog(AddFrame.this ,"添加失败");

                }
            }
        });
        jButton2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                AddFrame.this.setVisible(false);
                AddFrame.this.dispose();
            }
        });
    }
}
